#!/usr/bin/python
# -*- coding:UTF-8 -*-

class Friend(object):
    'Object'
    def __init__(self,id=0,name="",headurl=""):
        self.id=id
        self.name=name
        self.headurl=headurl

class User(object):
    'Object'
    def __init__(self):
        self.uid=0;
        self.name=""
        self.sex=0
        self.birthday=""
        self.tinyurl=""
        self.headurl=""
        self.mainurl=""
        self.hometown_location=None
        self.work_history=[]
        self.university_history=[]
        self.hs_history=[]
        self.contact_info=None
        self.books=None
        self.movies=None
        self.music=None
    def __getitem__(self,key):
        if hasattr(self,key):
            return getattr(self,key)
    def __setitem__(self,key,val):
        if hasattr(self,key):
            setattr(self,key,val)
    def toString(self):
        strs=[]
        strs.append("uid="+str(self.uid))
        strs.append("name="+str(self.name))
        strs.append("sex="+str(self.sex))
        strs.append("birthday="+str(self.birthday))
        strs.append("tinyurl="+str(self.tinyurl))
        strs.append("headurl="+str(self.headurl))
        strs.append("mainurl="+str(self.mainurl))
        strs.append("hometown="+str(self.hometown_location))
        return "\n".join(strs)


class HometownLocation(object):
    'Object'
    def __init__(self):
        self.country=""
        self.province=""
        self.city=""
    def __str__(self):
        return self.province+"."+self.city

class WorkInfo(object):
    'Object'
    def __init__(self):
        self.company_name=""
        self.escription=""
        self.start_date=""
        self.end_data=""

class UniversityInfo(object):
    'Object'
    def __init__(self):
        self.name=""
        self.year=""
        self.department=""
        
class HsInfo(object):
    'Object'
    def __init__(self):
        self.name=""
        self.grad_year=""

## Xiaonei                
class XiaoneiMethod(object):
    'API name'
    def __init__(self,name,maxParams=0,takesFile=False):
        self.methodName=name
        self.numParams=maxParams
        self. maxParamsWithSession=maxParams+6
        self.takesFile=takesFile
    def __str__(self):
        return self.methodName

class XiaoneiParam(object):
    'API parameters'
    def __init__(self,name=None):
        if name is None:
            self._paramName = "xn_sig"
        else:
            self._paramName = "xn_sig_"+name
            self._signatureName = name
    def getSignatureName(self):
        return self._signatureName
    def __str__(self):
        return self._paramName
    

class ProfileField(object):
    'Filed used when getting user infomation'
    def __init__(self,name,id):
        self.fieldName=name
        self._order=id
    def __str__(self):
        return self.fieldName
    def isName(self,n):
        return self.fieldName==n

class XiaoneiException(BaseException):
    'Exception'
    def __init__(self,code="-1",msg="Xiaonei Error"):
        self.message=msg
        self.errorcode=code
